package com.bosssoft.service.impl;

import com.bosssoft.entity.dto.FibBankDTO;
import com.bosssoft.enums.CopyPropertityEnum;
import com.bosssoft.exception.DaoException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bosssoft.mapper.FibBankMapper;
import com.bosssoft.entity.po.FibBankPO;
import com.bosssoft.service.FibBankService;
/**
 * @author 项昊天
 * @create 2021/8/17 16:41
 */
@Slf4j
@Service
public class FibBankServiceImpl extends ServiceImpl<FibBankMapper, FibBankPO> implements FibBankService {

  @Override
  public boolean addBank(FibBankDTO bankDTO) {
    try {
      FibBankPO bankPO = new FibBankPO();
      BeanUtils.copyProperties(bankDTO, bankPO);
      return this.baseMapper.insert(bankPO) > 0;
    } catch (DaoException e) {
      log.info("addBank出错");
    }
    return false;
  }

  @Override
  public boolean modifyBank(FibBankDTO bankDTO) {
    try {
      FibBankPO bankPO = new FibBankPO();
      BeanUtils.copyProperties(bankDTO, bankPO);
      return this.baseMapper.updateById(bankPO) > 0;
    } catch (DaoException e) {
      log.info("addBank出错");
      throw DaoException.error().setCodeAndMessage(CopyPropertityEnum.RESOURCE_NULL_ERROR);
    }
  }

  @Override
  public boolean banBankById(Long bankId, Integer status) {
    return this.baseMapper.banBankById(bankId, status) > 0;
  }

  @Override
  public boolean deleteBankById(Long bankId) {
    return this.baseMapper.deleteById(bankId) > 0;
  }
}
